/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model.game.disaster.plugin;

import java.awt.Image;
import java.util.Random;
import model.game.GameInterface;
import model.game.disaster.Disaster;
import model.utility.ImageUtility;

/**
 * Theft, lost maximum 100 money at the end of day. 10% chance
 */
public class Theft extends Disaster {

  /**
   * Keeps track whether this disaster is active
   */
  private boolean active_;

  /**
   * Random number generator
   */
  private Random random_;

  /**
   * Constructor
   */
  public Theft(GameInterface game) {
    super(game);
    active_ = false;
    random_ = new Random();
  }

  @Override
  public String getName() {
    return "Theft";
  }

  @Override
  public String getDescription() {
    return "A thief broke into your house and stole [max 100] last night";
  }

  @Override
  public void advanceDay() {
    active_ = false;
    if (game_.getGameTime().getDayCount() >= 3) {

      // 10% chance of happening every day
      if (random_.nextDouble() > 0.90) {

        // accident happens
        int lost_money = Math.min(random_.nextInt(201),
                game_.getInventory().getMoney());
        game_.addImportantMessage("A thief broke into your house! You lose " +
                game_.getConstants().getFormattedMoney(lost_money));
        game_.getInventory().addMoney(-lost_money);
        active_ = true;
      }
    }
  }

  @Override
  public void advanceTime() {
  }

  @Override
  public boolean isActive() {
    return active_;
  }

  public Image getImage() {
    return ImageUtility.loadImage("resources/pictures/disaster/theft.jpg");
  }

}
